package com.bigdata;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class HiveJdbcDemo {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";

    public static void main(String[] args) {


        int num = 100;
        String result = String.valueOf(num);
        System.out.println(result);
        System.out.println("" + num);



        Connection conn = null;
        PreparedStatement ps = null;
        try {
            Class.forName(driverName);

            // 获取连接
            conn = DriverManager.getConnection("jdbc:hive2://node03:10000/default", "root", "root");

//            PreparedStatement ps = conn.prepareStatement("select * from stu limit ?");
//            // 设置参数
//            ps.setInt(1, 3);
//
//            ResultSet rs = ps.executeQuery();
//
//            while (rs.next()) {
//                int id = rs.getInt("id");
//                String name = rs.getString("name");
//                System.out.println("id---" + id + ",name---" + name);
//            }

            ps = conn.prepareStatement("insert into stu values(?,?)");
            ps.setInt(1, 9);
            ps.setString(2, "hive");
            ps.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
